<template>
    <div>
        <el-form label-width="120px" :model="form">
            <el-form-item label="公司名称">
                <el-input v-model="form.name" size="small"></el-input>
            </el-form-item>
            <el-form-item label="公司地址">
                <el-input v-model="form.address" size="small">
                    <template slot="append">
                        <el-button type="primary" size="small" @click="geo">定位</el-button>
                    </template>
                </el-input>
            </el-form-item>
            <el-form-item label="地图信息" size="mini">
                <qqmap zoom="18" @poi-change="changePoi" :lat="form.lat" :lng="form.lng" />
            </el-form-item>
            <el-form-item label="联系电话">
                <el-input v-model="form.phone" size="small"></el-input>
            </el-form-item>
            <el-form-item label="广告语">
                <el-input v-model="form.demo" maxlength="20" size="small"> </el-input>
            </el-form-item>
            <el-form-item label="介绍" prop="note" key="note">
                <el-input type="textarea" v-model="form.note" key="note" size="small">
                </el-input>
            </el-form-item>
            <el-form-item label="客服签名" prop="chatSign" key="chatSign">
                <el-input type="textarea" v-model="form.chatSign" key="chatSign" size="small">
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="handleData" size="small">保存信息</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import qqmap from "@/components/qqmap.vue";

    export default {
        components: {qqmap},
        data() {
            return {
                form: {},
                rules: {
                    name: [{
                        required: true,
                        message: "请输入名称",
                        trigger: "blur"
                    }],
                },
            };
        },
        methods: {
            async handleData() {
                var self = this;
                var param = this.form;
                var res = await this.$HTTP.form(
                    "/tenantRest/sitetenant/updateCur.htm",
                    param
                );
                if (res.code == 0) {
                    self.$message({
                        message: "更新成功",
                        type: "success",
                    });
                } else {
                    self.$message.error(res.msg);
                }
            },
            async geo() {
                var param = {};
                param.address = this.form.address;
                var self = this;
                var result = await this.$HTTP.form("/tenantRest/area/lbs.htm", param);
                if (result.code == 0) {
                    self.form.lat = result.lat;
                    self.form.lng = result.lng;
                    if (result.provinceId) {
                        self.form.province = result.provinceId;
                    }
                    if (result.cityId) {
                        self.form.city = result.cityId;
                    }
                    if (result.countyId) {
                        self.form.county = result.countyId;
                    }
                }
            },
            async loadData() {
                var params = {};
                var result = await this.$HTTP.form("/tenantRest/sitetenant/cur.htm", params);
                if (result.code == 0) {
                    this.form = result;
                }
            },
            changePoi(event) {
                console.log(event);
                this.form.lat = event.lat;
                this.form.lng = event.lng;
            },
        },
        mounted() {
            this.loadData();
        },
    };
</script>

<style>
</style>